package com.sxxm.qxgl.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sxxm.qxgl.entity.UserMenu;
import com.sxxm.qxgl.mapper.UserMenuMapper;
import com.sxxm.qxgl.service.UserMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxxm.qxgl.vo.Result;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author qjw
 * @since 2021-09-22
 */
@Service
public class UserMenuServiceImpl extends ServiceImpl<UserMenuMapper, UserMenu> implements UserMenuService {
    UserMenuMapper userMenuMapper;
    public UserMenuServiceImpl(UserMenuMapper userMenuMapper){
        this.userMenuMapper = userMenuMapper;
    }

    @Override
    public Result cx(UserMenu userMenu) {
//        HashMap<String,Object> map = new HashMap<>();
//        map.put("UserId",userMenu.getUserId());
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("UserId",userMenu.getUserId());
        List<UserMenu> list = userMenuMapper.selectList(queryWrapper);
        List<Tree<String>> treeNodes = TreeUtil.build(list, "0",
                (treeNode, tree) -> {
                    tree.setId(String.valueOf(treeNode.getMenuId()));
                    tree.setParentId(String.valueOf(treeNode.getParentId()));
                    tree.setWeight(treeNode.getUserId());
                    tree.setName(treeNode.getName());
//                    tree.putExtra("status",treeNode.getStatus());
//                    tree.putExtra("imgUrl",treeNode.getImgUrl());
//                    tree.putExtra("appUrl",treeNode.getAppUrl());
//                    tree.putExtra("sortCode",treeNode.getSortCode());
                });
        return Result.ok().message("成功").data(treeNodes);
    }


}
